<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>文件上传处理</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.15.14/lib/theme-chalk/index.css">
  <script src="https://cdn.jsdelivr.net/npm/element-ui@2.15.14/lib/index.js"></script>
  <style>
    body {
      min-height: 100vh;
      margin: 0;
      background: linear-gradient(135deg, #e0e7ff 0%, #f0fdfa 100%);
      display: flex;
      align-items: center;
      justify-content: center;
      font-family: 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
    }
    #app {
      width: 100vw;
      height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .center-card {
      min-width: 400px;
      max-width: 480px;
      margin: auto;
      box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
      border-radius: 18px;
      background: #fff;
      padding: 36px 32px 32px 32px;
      text-align: center;
    }
    .main-title {
      font-size: 2.2rem;
      font-weight: bold;
      color: #3a3a3a;
      margin-bottom: 18px;
      letter-spacing: 2px;
    }
    .el-upload {
      width: 100%;
    }
    .el-upload__text {
      font-size: 1.1rem;
    }
    .el-upload__tip {
      color: #888;
    }
    .el-alert {
      margin-top: 24px;
    }
  </style>
</head>
<body>
  <div id="app">
    <el-card class="center-card" shadow="hover">
      <div class="main-title">上传股票数据文件</div>
      <div style="color:#888;margin-bottom:18px;">支持 Excel（.xls/.xlsx）、CSV、TXT 文件</div>
      <el-upload
        class="upload-demo"
        drag
        action="/uploadfile"
        :on-success="handleSuccess"
        :on-error="handleError"
        :show-file-list="false"
        :before-upload="beforeUpload"
        :data="{}"
      >
        <i class="el-icon-upload" style="font-size:38px;color:#409EFF;"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">仅支持 .xls, .xlsx, .csv, .txt 文件</div>
      </el-upload>
      <el-alert v-if="resultMsg" :title="resultMsg" type="success" show-icon></el-alert>
      <el-alert v-if="errorMsg" :title="errorMsg" type="error" show-icon></el-alert>
    </el-card>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: {
        resultMsg: '',
        errorMsg: ''
      },
      methods: {
        handleSuccess(response) {
          this.resultMsg = response.detail || '文件上传并处理成功';
          this.errorMsg = '';
        },
        handleError(err, file) {
          this.errorMsg = '文件上传失败';
          this.resultMsg = '';
        },
        beforeUpload(file) {
          const ext = file.name.split('.').pop().toLowerCase();
          const allow = ['xls', 'xlsx', 'csv', 'txt'];
          if (!allow.includes(ext)) {
            this.$message.error('仅支持 .xls, .xlsx, .csv, .txt 文件');
            return false;
          }
          return true;
        }
      }
    });
  </script>
</body>
</html> 